package com.tanhua.server.controller;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 刘付磊
 * @date 2021/11/20 0020
 */
@RequestMapping("/messages")
@RestController
public class MessagesContorller {

    @Autowired
    private MessagesService messagesService;

    @GetMapping("/userinfo")
    public ResponseEntity userinfo(String huanxinId){
        UserInfoVo vo= messagesService.userInfoByIdHuanXin(huanxinId);
        return ResponseEntity.ok(vo);
    }
    /*添加好友*/
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        String userId = map.get("userId").toString();
        Long friendId = Long.valueOf(userId);
        messagesService.contacts( friendId);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   String keyword){
        PageResult pr = messagesService.findFriends(page,pagesize,keyword);
        return ResponseEntity.ok(pr);
    }
}
